#include <iostream>
using namespace std;
// 轮胎类
class tyre_t {
  private:
    int m_radius; // 半径
    int m_width;  // 宽度
  public:
    tyre_t(int radius, int width);
    ~tyre_t();
    void show() const;
};

tyre_t::tyre_t(int radius, int width) : m_radius(radius), m_width(width)
{
    cout << "tyre_t() constructor" << endl;
}
tyre_t::~tyre_t()
{
    cout << "~tyre_t() destructor" << endl;
}
void tyre_t::show() const
{
    cout << "轮毂半径：" << this->m_radius << "inch" << endl;
    cout << "轮胎宽度：" << this->m_width << "mm" << endl;
}

// 引擎类
class engine_t {
  private:
    float m_displacement;

  public:
    engine_t(float displacement = 2.0);
    ~engine_t();
    void show() const;
};
engine_t::engine_t(float displacement) : m_displacement(displacement)
{
  cout << "engine_t() constructor" << endl;
}
engine_t::~engine_t()
{
  cout << "~engine_t() destructor" << endl;
}
void engine_t::show() const
{
    cout << "排量：" << this->m_displacement << "L" << endl;
}
// 汽车类
class care_t {
  private:
    int      m_price;  // 价格
    tyre_t   m_tyre;   // 轮胎
    engine_t m_engine; // 引擎
  public:
    care_t(int price, int radius, int width);
    ~care_t();
    void show() const;
};
/*指明m_tyre对象的初始化方式*/
care_t::care_t(int price, int radius, int width) : m_price(price), m_tyre(radius, width)
{
  cout << "care_t() constructor" << endl;
}
care_t::~care_t()
{
  cout << "~care_t() destructor" << endl;
}
void care_t::show() const
{
    cout << "价格：" << this->m_price << "￥" << endl;
    this->m_tyre.show();
    this->m_engine.show();
}

/*
(1)封闭类对象生成时，先执行所有成员对象的构造函数，然后才执行封闭类自己的构造函数。成员对象构造函数的执行次序和成员对象在类定义中的次序一致,
   与它们在构造函数初始化列表中出现的次序无关。
(2)当封闭类对象消亡时，先执行封闭类的析构函数，然后再执行成员对象的析构函数，成员对象析构函数的执行次序和构造函数的执行次序相反，即先构造的后析构，
   这是 C++ 处理此类次序问题的一般规律。
*/
int main()
{
    care_t car(200000, 19, 245);
    car.show();
    return 0;
}
